package com.kingint.web.portal.serve.controller;


import com.kingint.mbg.dto.rushHouse.RushHouseFrontDetails;
import com.kingint.mbg.dto.rushHouse.RushHouseFrontParam;
import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import com.kingint.mbg.ser.entity.SerCheckRoom;
import com.kingint.web.util.validateUtil.ValidList;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.portal.serve.service.RushHouseService;
import com.kingint.mbg.ser.entity.SerRushHouse;

import java.util.List;


/**
 * @描述：发布赶房表控制类
 * @作者: wxh
 * @日期: 2021-01-06
 */
@RestController
@RequestMapping("/rushHouse")
@Api(value = "RushHouseController", description = "前端发布赶房表")
@CrossOrigin
public class RushHouseController {

    @Autowired
    public RushHouseService serRushHouseService;


    @ApiOperation(value = "添加发布赶房表")
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody RushHouseFrontParam rushHouseFrontParam) {
        int i = serRushHouseService.insertRushHouseInfo(rushHouseFrontParam);
        if (i > 0) {
            return K.ok().data(i);
        } else {
            return K.error();
        }
    }

    //查询待接单的赶房工单
    @ApiOperation(value = "获取待接单的赶房工单")
    @GetMapping("/getWaitReceiveList")
    public Object getWaitReceiveList() {
        List<RushHouseFrontParam> params = serRushHouseService.getWaitReceiveList();
        return K.ok().data(params);
    }

    @ApiOperation(value = "清洁人员接单")
    @GetMapping("/receiveOrderInfo")
    public Object receiveOrderInfo(@RequestParam(value = "id") Integer id) {
        Integer i = serRushHouseService.receiveOrderInfo(id);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }


    @ApiOperation(value = "获取对应的赶房表单的详情信息")
    @GetMapping("/getRushHouseInfo")
    public Object getItem(@RequestParam("id") Integer id) {
        RushHouseFrontDetails rushHouseInfoById = serRushHouseService.getRushHouseInfoById(id);
        return K.ok().data(rushHouseInfoById);
    }

    //查询 查房，查遗留，消费等
    @ApiOperation(value = "查询 查房，查遗留，消费等")
    @GetMapping("/getCheckRoomInfo")
    public Object getCheckRoomInfo(@RequestParam("id") Integer id) {
        SerCheckRoom serCheckRoom = serRushHouseService.getCheckRoomInfo(id);
        return K.ok().data(serCheckRoom);
    }

    @ApiOperation(value = "提交查询 查房，查遗留，消费等相关信息完成查房")
    @PostMapping("/finishCheckRoomInfo")
    public Object finishCheckRoomInfo(@RequestBody SerCheckRoom serCheckRoom) {
        int i = serRushHouseService.finishCheckRoomInfo(serCheckRoom);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "提交布草相关信息")
    @PostMapping("/submitArrangeInfo")
    public Object submitArrangeInfo(@RequestBody RushHouseFrontDetails details) {
        int i = serRushHouseService.submitArrangeInfo(details);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "相关状态改变，1.开始赶房，2.完成赶房，3.无需清洁")
    @GetMapping("/startRushHouseInfo")
    public Object startRushHouseInfo(@RequestParam(value = "status", defaultValue = "0") Integer status,
                                     @RequestParam("id") Integer id) {
        int i = serRushHouseService.startRushHouseInfo(status, id);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "验收人验收赶房工单(1，验收，0，拒绝）,id为workId")
    @GetMapping("/completeRushHouseInfo")
    public Object completeRushHouseInfo(@RequestParam(value = "status", defaultValue = "0") Integer status,
                                        @RequestParam("id") Integer id) {
        int i = serRushHouseService.completeRushHouseInfo(status, id);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

}